package biz.obake.team.touchprotector.f;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.f.l;
import biz.obake.team.touchprotector.tpservice.TPService;
import d.e;

public final class j implements l {
    /* access modifiers changed from: private */

    /* renamed from: b  reason: collision with root package name */
    public final ViewGroup f1630b;

    /* renamed from: c  reason: collision with root package name */
    private StringBuilder f1631c;

    /* renamed from: d  reason: collision with root package name */
    private final Handler f1632d = new Handler();
    private final Runnable e;
    private final Runnable f;
    /* access modifiers changed from: private */
    public final k g;

    static final class a implements View.OnClickListener {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ j f1633b;

        a(j jVar) {
            this.f1633b = jVar;
        }

        public final void onClick(View view) {
            if (view != null) {
                this.f1633b.k(((Button) view).getText().toString());
                return;
            }
            throw new e("null cannot be cast to non-null type android.widget.Button");
        }
    }

    static final class b implements View.OnTouchListener {

        /* renamed from: b  reason: collision with root package name */
        public static final b f1634b = new b();

        b() {
        }

        public final boolean onTouch(View view, MotionEvent motionEvent) {
            d.h.b.c.b(motionEvent, "event");
            if (motionEvent.getAction() != 0) {
                return false;
            }
            biz.obake.team.touchprotector.c.x();
            return false;
        }
    }

    static final class c implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ j f1635b;

        c(j jVar) {
            this.f1635b = jVar;
        }

        public final void run() {
            AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
            alphaAnimation.setDuration(250);
            this.f1635b.f1630b.startAnimation(alphaAnimation);
            this.f1635b.f1630b.setVisibility(0);
            this.f1635b.l(true);
            this.f1635b.g.s();
        }
    }

    static final class d implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ j f1636b;

        d(j jVar) {
            this.f1636b = jVar;
        }

        public final void run() {
            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
            alphaAnimation.setDuration(250);
            this.f1636b.f1630b.startAnimation(alphaAnimation);
            this.f1636b.f1630b.setVisibility(8);
            this.f1636b.l(false);
            this.f1636b.g.s();
        }
    }

    public j(k kVar) {
        d.h.b.c.c(kVar, "mPV");
        this.g = kVar;
        View findViewById = this.g.findViewById(R.id.pinPanel);
        d.h.b.c.b(findViewById, "mPV.findViewById(R.id.pinPanel)");
        this.f1630b = (ViewGroup) findViewById;
        i();
        this.e = new c(this);
        this.f = new d(this);
    }

    @SuppressLint({"ClickableViewAccessibility"})
    private final void i() {
        int childCount = this.f1630b.getChildCount();
        int i = 0;
        while (i < childCount) {
            View childAt = this.f1630b.getChildAt(i);
            if (childAt != null) {
                Button button = (Button) childAt;
                button.setOnClickListener(new a(this));
                button.setOnTouchListener(b.f1634b);
                i++;
            } else {
                throw new e("null cannot be cast to non-null type android.widget.Button");
            }
        }
    }

    /* access modifiers changed from: private */
    public final void k(String str) {
        this.f1632d.removeCallbacks(this.f);
        this.f1632d.postDelayed(this.f, 3000);
        StringBuilder sb = this.f1631c;
        if (sb != null) {
            sb.append(str);
            String valueOf = String.valueOf(this.f1631c);
            if (d.h.b.c.a(valueOf, biz.obake.team.touchprotector.e.a.b())) {
                TPService.k("UnlockForce", "PinAuthentication");
                this.f1632d.removeCallbacks(this.f);
                this.f1630b.setVisibility(8);
            } else if (valueOf.length() >= 8) {
                biz.obake.team.touchprotector.g.e.a(R.string.toast_pin_incorrect);
                this.f1632d.removeCallbacks(this.f);
                this.f.run();
            }
        } else {
            d.h.b.c.f();
            throw null;
        }
    }

    /* access modifiers changed from: private */
    public final void l(boolean z) {
        int childCount = this.f1630b.getChildCount();
        int i = 0;
        while (i < childCount) {
            View childAt = this.f1630b.getChildAt(i);
            if (childAt != null) {
                ((Button) childAt).setEnabled(z);
                i++;
            } else {
                throw new e("null cannot be cast to non-null type android.widget.Button");
            }
        }
    }

    public void a() {
        this.f1632d.removeCallbacksAndMessages((Object) null);
        this.f1630b.setVisibility(8);
        l(false);
    }

    public boolean b(MotionEvent motionEvent) {
        d.h.b.c.c(motionEvent, "event");
        return l.a.a(this, motionEvent);
    }

    public void c() {
        l.a.d(this);
    }

    public void d() {
        l.a.b(this);
    }

    public final boolean j() {
        return this.f1630b.getVisibility() == 0;
    }

    public final boolean m() {
        if (!biz.obake.team.touchprotector.e.a.c()) {
            return false;
        }
        this.f1631c = new StringBuilder();
        this.e.run();
        this.f1632d.removeCallbacks(this.f);
        this.f1632d.postDelayed(this.f, 3250);
        return true;
    }
}
